(require 'workspace-model)

(defun for-each-folder (folder body)
  (let* ((dir-list '())
	 (folder (if (null folder) "." folder)))
    (funcall body folder)
    (dolist (file (directory-files folder))
      (catch 'continue
	(when (or (equal file ".") 
		  (equal file ".."))
	  (throw 'continue nil))
	(setq path (concat folder "/" file))
	(when (file-directory-p path)
	  (push path dir-list))))
    (dolist (path dir-list)
      (for-each-folder path body))))


(defun import-as-files(directory &optional postfix-list)
  "import all files from a workspace"
  (interactive "sdirectory: ")
  (clear-pool)
  (let* ((postfix-list (if (null postfix-list)
			   *postfix-list*
			 postfix-list)))
    (for-each-folder directory
		     '(lambda (directory)
		       (dolist (file (directory-files directory))
			 (catch 'continue
			   (setq path (concat directory "/" file))
			   (when (file-directory-p path)
			     (throw 'continue nil))
			   (dolist (postfix postfix-list)
			     (when (string-match (concat postfix "$") file)
			       (read-file path)))))))))

(defun find-as-file (classname)
  (let ((buffer nil))
    (when classname
      (setq buffer (get-class classname))
      (when buffer
	(find-file (oref buffer path))))))

(provide 'find-all-file)


